<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        .layui-form-item  {
            width: auto;
            padding-right: 10px;
            padding-left: 500px;
            line-height: 38px;

        }

        /*// 去掉input边框*/
        .layui-input {
            outline: none;
            border: none;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div style="padding-left: 694px" >
                <img data-anim="layui-anim-scaleSpring" class="layui-upload layui-anim" id="id_upload_img"
                     src="https://www.jq22.com/img/cs/500x500-2.png" style="border-radius: 5%; width: 5%">
<!--                <div class="layui-word-aux">点击更换我的头像</div>-->
<!--                <div class="layui-word-aux">上传图片限制大小 600kb</div>-->
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <label for="username"></label>
                    <input type="text" name="username" value="" class="layui-input" id="username" readonly disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label "></label>
                <div class="layui-input-block">
                    <label>
                        <input type="number" name="phone" id="phone" lay-reqtext="手机不能为空"
                               placeholder="请输入手机" value="" class="layui-input" readonly disabled>
                    </label>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <label>
                        <input type="email" name="email" id="email" placeholder="请输入邮箱" value=""
                               class="layui-input" readonly disabled>
                    </label>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">

                    <label>
                        <input name="Remarks" id="Remarks" class="layui-input" readonly disabled></input>
                    </label>

                </div>
            </div>

        </div>
    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'miniTab', 'upload'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const pk = localStorage.getItem("pk");
        const headers = {
            'Authorization': localStorage.getItem('token')
        };
        const upload = layui.upload;
        const uploadInst = upload.render({
            elem: '#id_upload_img',
            url: '/user/upload_img/',
            size: 600, //限制文件大小，单位 KB
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#id_upload_img').attr('src', result); //图片链接（base64）
                });
            },
            done: function (res) {
                //如果上传失败
                if (res.status > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html(
                    '<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        if (headers.Authorization == null || headers.Authorization == '') {
            window.location.href = "page/login.html";
        }

        // 初始化表单数据
        $.ajax({
            url: 'http://127.0.0.1:8000/user/user/' + pk + '/',
            type: "GET",
            headers: headers,
            success: function (res) {
                if (pk) {
                    $('#username').val(res.data.username);
                    $('#phone').val(res.data.phone);
                    $('#email').val(res.data.email);
                    $('#Remarks').val(res.data.Remarks);
                } else {
                    window.location.href = "page/login.html";
                }
            }
        })
        return false;
    });
</script>
<script src="../js/yanhua.js" charset="utf-8"></script>
</body>
</html>